﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using LView.CMS.IServices;
using LView.CMS.ViewModels;
using LView.CMS.Core.Helper;

namespace LView.CMS.Site.Controllers
{
    public class TestPageController : Controller
    {
        private readonly ITestPageService _testPageService;
        public TestPageController(ITestPageService testPageService)
        {
            _testPageService = testPageService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public async Task<string> LoadDataAsync([FromQuery] PageModel input)
        {
            var result = await _testPageService.LoadDataAsync(input);
            return JsonHelper.ObjectToJSON(result);
        }

        [HttpGet]
        public IActionResult AddOrModify()
        {
            return View();
        }

        [HttpPost]
        [Route("/TestPage/AddOrModify")]
        public async Task<string> AddOrModifyAsync([FromForm] TestPageAddOrModify input)
        {
            var result = await _testPageService.AddOrModify(input);
            return JsonHelper.ObjectToJSON(result);
        }

        [HttpPost]
        public async Task<string> Delete(string[] testPageId)
        {
            var result = await _testPageService.DeleteIdsAsync(testPageId);
            return JsonHelper.ObjectToJSON(result);
        }
    }
}
